package main

import (
	"path"

	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/sqlite"
)

type Request struct {
	URL      string `gorm:"type:TEXT(255);unique_index" json:"url"`
	Header   string `gorm:"type:TEXT(2048)" json:"header"`
	Response string `gorm:"type:TEXT(2048)" json:"response"`
}

var requests []*Request

func init() {
	db_file := path.Join(cnf.Srv.DB)
	db, err := gorm.Open("sqlite3", db_file)
	if err != nil {
		panic(err)
	}

	// 自动迁移模式
	db.AutoMigrate(&Request{})
	db.Find(&requests)
}
